package com.googlecode.connectlet.vspkm;

import com.googlecode.connectlet.Connector;
import com.googlecode.connectlet.misc.BroadcastServer;
import com.googlecode.connectlet.misc.DumpFilterFactory;
import com.googlecode.connectlet.misc.ProxyServer;
import com.googlecode.connectlet.ssl.CertKey;
import com.googlecode.connectlet.ssl.CertMap;
import com.googlecode.connectlet.util.ClassPath;

public class TestVspkmProxy {
	public static void main(String[] args) throws Exception {
		CertKey certKey = new CertKey(ClassPath.getInstance("../conf/localhost.pfx"), "changeit", "PKCS12");
		CertMap certMap = new CertMap();
		certMap.add(ClassPath.getInstance("../conf/localhost.cer"));
		VspkmFilterFactory vff = new VspkmFilterFactory(certKey, certMap);

		Connector connector = new Connector();
		BroadcastServer broadcastServer = new BroadcastServer(2323);
//		ProxyServer broadcastServer = new ProxyServer(connector, 2323, "localhost", 8080);
		broadcastServer.getFilterFactories().add(vff);
		broadcastServer.getFilterFactories().add(new DumpFilterFactory());
		connector.add(broadcastServer);

		ProxyServer proxyServer = new ProxyServer(connector, 2424, "localhost", 2323);
		proxyServer.getRemoteFilterFactories().add(vff);
		proxyServer.getRemoteFilterFactories().add(new DumpFilterFactory().
				setDumpStream(System.err).setUseClientMode(true));
		connector.add(proxyServer);

		while (true) {
			while (connector.doEvents()) {/**/}
			Thread.sleep(10);
		}
	}
}